package com.backpackerxl.blog.dao;

import com.backpackerxl.blog.model.Tag;
import com.backpackerxl.blog.vomodel.BlogCount;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Author by：Backpackersxl
 * Date: 2021/5/5/005
 * Time: 23:41
 **/
public interface TagRepository extends JpaRepository<Tag, Long>, JpaSpecificationExecutor<Tag> {
    Tag findByName(String name);

    @Query("select t from Tag t ")
    List<Tag> findTop(Pageable pageable);

    @Query("select t.name, size(t.blogs) as total from Tag t group by t.id")
    List<BlogCount> findCountTag();
}
